package com.example.datasourcedemo.exception;

import com.example.datasourcedemo.enums.CommEnum;
import lombok.Getter;


/**
 * @author
 * @desc
 **/
@Getter
public class CommException extends RuntimeException {

    private static final String MESSAGE_FORMAT = "ErrorCode:%d ; ErrorMessage:%s ; ExceptionMessage:%s ; ";

    private Integer errorCode;
    private String errorMessage;

    public CommException() {
        super();
    }

    public CommException(String message, Throwable cause) {
        super(message, cause);
    }

    public CommException(String message) {
        super(message);
    }

    public CommException(Throwable cause) {
        super(cause);
    }

    /**
     * 构造方法
     *
     * @param errCode
     * @param
     */
    public CommException(Integer errCode, String errMsg) {
        super(String.format(MESSAGE_FORMAT, errCode, errMsg, "null"));
        this.errorCode = errCode;
        this.errorMessage = errMsg;
    }


    /**
     * 基于commEnum的构造方法
     *
     * @param commEnum
     */
    public CommException(CommEnum<Integer> commEnum) {
        super(String.format(MESSAGE_FORMAT, commEnum.getCode(), commEnum.getContent(), "null"));
        this.errorCode = commEnum.getCode();
        this.errorMessage = commEnum.getContent();
    }

    /**
     * 基于commEnum的构造方法
     *
     * @param commEnum
     * @param message
     */
    public CommException(CommEnum<Integer> commEnum, String message) {
        super(String.format(MESSAGE_FORMAT, commEnum.getCode(), message, "null"));
        this.errorCode = commEnum.getCode();
        this.errorMessage = message;
    }




}
